from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2021-08-24 14:13:00.534039
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Tue, 24, Aug, 2021
Time: 14:13:06
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -45.7688
Nobs: 393.000 HQIC: -46.3182
Log likelihood: 4243.61 FPE: 5.34153e-21
AIC: -46.6789 Det(Omega_mle): 4.26043e-21
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.432921 0.095276 4.544 0.000
L1.Burgenland 0.101918 0.049279 2.068 0.039
L1.Kärnten -0.115774 0.024490 -4.727 0.000
L1.Niederösterreich 0.165094 0.106244 1.554 0.120
L1.Oberösterreich 0.137414 0.104359 1.317 0.188
L1.Salzburg 0.285269 0.051658 5.522 0.000
L1.Steiermark 0.019829 0.068517 0.289 0.772
L1.Tirol 0.110451 0.054050 2.043 0.041
L1.Vorarlberg -0.116638 0.048867 -2.387 0.017
L1.Wien -0.013648 0.094218 -0.145 0.885
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.012622 0.221570 0.057 0.955
L1.Burgenland -0.049484 0.114601 -0.432 0.666
L1.Kärnten 0.035082 0.056953 0.616 0.538
L1.Niederösterreich -0.250527 0.247077 -1.014 0.311
L1.Oberösterreich 0.536785 0.242692 2.212 0.027
L1.Salzburg 0.315369 0.120133 2.625 0.009
L1.Steiermark 0.114867 0.159339 0.721 0.471
L1.Tirol 0.306708 0.125697 2.440 0.015
L1.Vorarlberg -0.011335 0.113642 -0.100 0.921
L1.Wien 0.001908 0.219109 0.009 0.993
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.250737 0.048406 5.180 0.000
L1.Burgenland 0.090505 0.025037 3.615 0.000
L1.Kärnten -0.003659 0.012442 -0.294 0.769
L1.Niederösterreich 0.222302 0.053978 4.118 0.000
L1.Oberösterreich 0.164680 0.053020 3.106 0.002
L1.Salzburg 0.038055 0.026245 1.450 0.147
L1.Steiermark 0.011363 0.034810 0.326 0.744
L1.Tirol 0.071108 0.027461 2.589 0.010
L1.Vorarlberg 0.056188 0.024827 2.263 0.024
L1.Wien 0.099882 0.047868 2.087 0.037
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.181878 0.047340 3.842 0.000
L1.Burgenland 0.045641 0.024485 1.864 0.062
L1.Kärnten -0.006919 0.012168 -0.569 0.570
L1.Niederösterreich 0.132324 0.052790 2.507 0.012
L1.Oberösterreich 0.314682 0.051853 6.069 0.000
L1.Salzburg 0.098562 0.025667 3.840 0.000
L1.Steiermark 0.139140 0.034044 4.087 0.000
L1.Tirol 0.073632 0.026856 2.742 0.006
L1.Vorarlberg 0.055350 0.024280 2.280 0.023
L1.Wien -0.034816 0.046814 -0.744 0.457
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.214212 0.094283 2.272 0.023
L1.Burgenland -0.059775 0.048766 -1.226 0.220
L1.Kärnten -0.035500 0.024235 -1.465 0.143
L1.Niederösterreich 0.097775 0.105137 0.930 0.352
L1.Oberösterreich 0.183792 0.103272 1.780 0.075
L1.Salzburg 0.259610 0.051120 5.078 0.000
L1.Steiermark 0.081000 0.067803 1.195 0.232
L1.Tirol 0.122286 0.053487 2.286 0.022
L1.Vorarlberg 0.113664 0.048358 2.350 0.019
L1.Wien 0.026855 0.093236 0.288 0.773
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.026152 0.073481 0.356 0.722
L1.Burgenland 0.026630 0.038006 0.701 0.484
L1.Kärnten 0.050436 0.018888 2.670 0.008
L1.Niederösterreich 0.198775 0.081940 2.426 0.015
L1.Oberösterreich 0.344891 0.080486 4.285 0.000
L1.Salzburg 0.047240 0.039841 1.186 0.236
L1.Steiermark -0.002250 0.052843 -0.043 0.966
L1.Tirol 0.114382 0.041686 2.744 0.006
L1.Vorarlberg 0.061756 0.037688 1.639 0.101
L1.Wien 0.133326 0.072665 1.835 0.067
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.186306 0.089421 2.083 0.037
L1.Burgenland 0.021353 0.046251 0.462 0.644
L1.Kärnten -0.057439 0.022985 -2.499 0.012
L1.Niederösterreich -0.121829 0.099715 -1.222 0.222
L1.Oberösterreich 0.194374 0.097945 1.985 0.047
L1.Salzburg 0.030335 0.048483 0.626 0.532
L1.Steiermark 0.299334 0.064306 4.655 0.000
L1.Tirol 0.493614 0.050728 9.731 0.000
L1.Vorarlberg 0.067108 0.045863 1.463 0.143
L1.Wien -0.110192 0.088427 -1.246 0.213
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.159178 0.097420 1.634 0.102
L1.Burgenland -0.006013 0.050388 -0.119 0.905
L1.Kärnten 0.062700 0.025041 2.504 0.012
L1.Niederösterreich 0.193479 0.108635 1.781 0.075
L1.Oberösterreich -0.116017 0.106707 -1.087 0.277
L1.Salzburg 0.243711 0.052820 4.614 0.000
L1.Steiermark 0.153051 0.070058 2.185 0.029
L1.Tirol 0.049576 0.055266 0.897 0.370
L1.Vorarlberg 0.121225 0.049966 2.426 0.015
L1.Wien 0.142523 0.096338 1.479 0.139
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.488773 0.052829 9.252 0.000
L1.Burgenland -0.010601 0.027325 -0.388 0.698
L1.Kärnten -0.009582 0.013579 -0.706 0.480
L1.Niederösterreich 0.199189 0.058911 3.381 0.001
L1.Oberösterreich 0.262076 0.057865 4.529 0.000
L1.Salzburg 0.020558 0.028643 0.718 0.473
L1.Steiermark -0.023453 0.037991 -0.617 0.537
L1.Tirol 0.067311 0.029970 2.246 0.025
L1.Vorarlberg 0.059077 0.027096 2.180 0.029
L1.Wien -0.050789 0.052242 -0.972 0.331
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.017682 0.078648 0.135961 0.129991 0.042591 0.067821 0.003188 0.177083
Kärnten 0.017682 1.000000 -0.057527 0.129107 0.046940 0.067935 0.457300 -0.094200 0.096381
Niederösterreich 0.078648 -0.057527 1.000000 0.286719 0.085864 0.274430 0.013107 0.147961 0.249881
Oberösterreich 0.135961 0.129107 0.286719 1.000000 0.176571 0.289886 0.161197 0.117958 0.134006
Salzburg 0.129991 0.046940 0.085864 0.176571 1.000000 0.128375 0.053908 0.109777 0.048102
Steiermark 0.042591 0.067935 0.274430 0.289886 0.128375 1.000000 0.126508 0.086555 -0.023502
Tirol 0.067821 0.457300 0.013107 0.161197 0.053908 0.126508 1.000000 0.039769 0.118838
Vorarlberg 0.003188 -0.094200 0.147961 0.117958 0.109777 0.086555 0.039769 1.000000 -0.046365
Wien 0.177083 0.096381 0.249881 0.134006 0.048102 -0.023502 0.118838 -0.046365 1.000000